package net.fdukedom.epicurus.plugin;

import net.fdukedom.epicurus.domain.entity.Plugin;
import net.fdukedom.epicurus.domain.entity.Extension;

import java.util.Map;
import java.util.Set;

/**
 * @author Dmitry Y. Kochelaev
 */
public class ExtensionsLoader extends CollectionLoader<Plugin, Extension> {
    public ExtensionsLoader(Plugin plugin) {
        super(plugin);
    }

    public Extension parseAttributes(Map<String, String> attributes) {
        return new Extension(attributes.get("class"), attributes.get("pointName"), item);
    }

    public Set<Extension> getLoadedCollection() {
        return item.getExtensions();
    }

    public void disposeElement(Extension element) {
        item.getExtensions().remove(element);
        element.setPlugin(null);
    }

    public void addElement(Extension element) {
        element.setPlugin(item);
        item.getExtensions().add(element);
    }
}